package com.zbcz.crm.adapter

import android.content.Context
import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.zbcz.crm.R
import com.zbcz.crm.bean.CommonSpinnerBean

class CustomSpinnerAdapter(context: Context, items: Array<CommonSpinnerBean>) :
    ArrayAdapter<CommonSpinnerBean>(context, android.R.layout.simple_spinner_item, items) {

    override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = super.getDropDownView(position, convertView, parent)
        val textView = view.findViewById<TextView>(android.R.id.text1)
        val item = getItem(position)
        if (position == 0) {
            textView.setTextColor(ContextCompat.getColor(context, R.color.text_color_hint))
        } else {
            textView.setTextColor(ContextCompat.getColor(context, R.color.black))
        }
        textView.text = item?.title

        return view
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
        val view = super.getView(position, convertView, parent)
        val textView = view.findViewById<TextView>(android.R.id.text1)

        if (position == 0) {
            textView.setTextColor(ContextCompat.getColor(context, R.color.text_color_hint))
        } else {
            textView.setTextColor(ContextCompat.getColor(context, R.color.black))
        }
        val item = getItem(position)
        textView.text = item?.title
        return view
    }
}
